function show() {
    console.log('fdfdf');
    let result = document.getElementById('resultContent').value;
    let resultView = document.getElementById('showTable');
    resultView.innerHTML = formate(result);
}
document.getElementById('showButton').onclick = () => {
    show()
};

document.getElementById('cleanButton').onclick = () => {
    document.getElementById('resultContent').value = "";
};

chrome.extension.onRequest.addListener((request, sender, sendResponse) => {
    console.log(request);
    document.getElementById('resultContent').value = '"' + request + '"';
    show();
});

function formate(source) {
    r = ""
    if (source.startsWith("<table")) {
        r = source;
    } else {
        let sss = JSON.parse(source);
        let arr = JSON.parse(sss);
        r += "<table border='1'><tr>"
        r += "<th>序号</th>\n"
        for (let field of arr[0]) {
            r += "<th>" + field + "</th>"
        }
        r += "</tr>\n"
        if (arr[1] != null) {
            let index = 1;
            for (let vs of arr[1]) {
                r += "<tr><td>" + index + "</td>"
                index++;
                for (let v of vs) {
                    r += "<td>" + v + "</td>"
                }
                r += "</tr>\n"
            }
        }
        r += "</table>"
    }
    return r;
}